home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 7.1 KB | 349 lines | [TEXT/MPS ] |
- /*
- File: StaticLetter.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __STATICLETTER__
- #include "StaticLetter.h"
- #endif
-
- #ifndef __RECIPIENT__
- #include "Recipient.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __RESOURCES__
- #include "Resources.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include "ToolUtils.h"
- #endif
-
- #ifndef __STRING__
- #include "String.h"
- #endif
-
- #pragma segment TStaticLetter
-
- /***********************************|****************************************/
-
- TStaticLetter::TStaticLetter
- (
- TRecipient* to,
- TRecipient* from,
- const TRString& subject,
- const TRString& content
- ):
- TLetter (),
- fTo ( to ),
- fFrom ( from ),
- fSubject ( subject ),
- fContent ( content ),
- fTemplate ( nil )
- {
- }
-
- /***********************************|****************************************/
-
- TStaticLetter::TStaticLetter
- (
- TRecipient* to,
- TRecipient* from,
- const TRString& subject,
- const TRString& content ,
- const ResType templateType,
- short templateID
- ):
- TLetter (),
- fTo ( to ),
- fFrom ( from ),
- fSubject ( subject ),
- fContent ( content ),
- fTemplate ( nil )
- {
- LoadTemplate ( templateType, templateID );
- }
-
- /***********************************|****************************************/
-
- TStaticLetter::~TStaticLetter ()
- {
- if ( fTemplate )
- ::ReleaseResource ( fTemplate );
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::LoadTemplate ( const ResType templateType, short templateID )
- {
- if ( fTemplate )
- ::ReleaseResource ( fTemplate );
-
- fTemplate = ::GetResource ( templateType, templateID );
-
- return fTemplate != nil;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::SetTemplateItem ( unsigned short zeroBasedItemIndex, const char* replaceString )
- {
- Boolean result = false;
-
- if ( fTemplate && zeroBasedItemIndex <= 9 && replaceString )
- {
- Byte targetString [ 2 ] = { '^', '0' };
- targetString [ 1 ] += (Byte) zeroBasedItemIndex;
- result = ::Munger ( fTemplate, 0, targetString, 2, (Ptr) replaceString, ::strlen ( replaceString ) ) >= 0;
- }
-
- return result;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetLetterID ( BLJLetterID& ) const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetReplyID ( BLJLetterID& ) const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetConversationID ( BLJLetterID& ) const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetSendTimeStamp (BLJTime&) const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetLetterPriority (LetterPriority& priority) const
- {
- priority = highPriority;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetSubject (RString& subject) const
- {
- fSubject.GetString ( subject, kRStringMaxBytes );
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::IsLetterAutoForwarded (Boolean& yesItIs) const
- {
- yesItIs = false;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::IsLetterAutoReply (Boolean& yesItIs) const
- {
- yesItIs = false;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::CanLetterBeAutoForwarded (Boolean& yesItCan) const
- {
- yesItCan = false;
- return true;
- }
-
- /***********************************|****************************************/
-
- unsigned short
- TStaticLetter::GetRecipientCount(RecipientTypeSet type) const
- {
- return type == fromRecipient || type == toRecipient ? 1 : 0;
- }
-
- /***********************************|****************************************/
-
- TRecipient*
- TStaticLetter::GetRecipient (RecipientTypeSet type, unsigned short index ) const
- {
- if ( index != 1 )
- return nil;
- else if ( type == fromRecipient )
- return fFrom;
- else if ( type == toRecipient )
- return fTo;
- else
- return nil;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetRecipientStatus(RecipientTypeSet type, unsigned short index, RecipientStatusSet& status ) const
- {
- TRecipient* recipient = GetRecipient ( type, index );
-
- if ( recipient )
- {
- status = recipient->GetStatus ( );
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::SetRecipientStatus(RecipientTypeSet type, unsigned short index, RecipientStatusSet status )
- {
- TRecipient* recipient = GetRecipient ( type, index );
-
- if ( recipient )
- {
- return recipient->SetStatus ( status );
- }
- else
- {
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- unsigned short
- TStaticLetter::GetUnknownRecipientCount() const
- {
- return 0;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::DeliveryReceiptRequested(Boolean &yesItIs) const
- {
- yesItIs = true;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::NonDeliveryReportRequested (Boolean& yesItIs) const
- {
- yesItIs = true;
- return true;
- }
-
- /***********************************|****************************************/
-
- unsigned long TStaticLetter::GetContentTypeCount ( ) const
- {
- return 1;
- }
-
- /***********************************|****************************************/
-
- OSType TStaticLetter::GetContentType ( unsigned long i ) const
- {
- if ( ( i == 1 ) )
- return 'TEXT';
-
- return '\?\?\?\?';
- }
-
- /***********************************|****************************************/
-
- unsigned long TStaticLetter::GetSegmentCount ( OSType contentType ) const
- {
- return 1; // content only
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetSegmentInfo(OSType contentType, unsigned long index, BLJLetterBlockType& blockType, long& blockLength) const
- {
- if ( ( contentType == 'TEXT' ) && ( index == 1 ) )
- {
- blockType.type = 'TEXT';
- blockType.creator = 'BLoJ';
-
- blockLength = fTemplate ? ::SizeResource ( fTemplate ) : 0;
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /***********************************|****************************************/
-
- Boolean
- TStaticLetter::GetSegmentData ( OSType contentType, unsigned long index, unsigned long offset, void* buffer, long& count ) const
- {
- if ( ( contentType == 'TEXT' ) && ( index == 1 ) )
- {
- count = fTemplate ? ::SizeResource ( fTemplate ) : 0;
-
- if ( offset < count )
- {
- ::BlockMove ( *fTemplate + offset, buffer, count - offset );
- }
- else
- {
- count = 0;
- }
-
- return true;
- }
- else
- {
- count = 0;
- return false;
- }
- }
-
- /***********************************|****************************************/
-